<extend name="extends/extend" />
<block name="loadCss">
</block>
<block name="script">
    <!-- sweetalert js -->
    <script src="__admin__/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script>
        $(document).ready(function () {
            $('.batchUpdate').on('click',function () {
                var sortInput   =   $('.table td .sortInput:input');
                console.log(sortInput);
                if(sortInput.length > 0){
                    var url = $(this).data('url');
                    $.get(url, sortInput.serialize(), function (data) {
                        swal({title: data.msg, icon: data.code?'success':'warning',dangerMode: true,}).then(function () {
                            location.reload(true)
                        });
                    }, 'json');
                }else{
                    swal({title: '当前没有数据无法排序呢!', icon: "warning",dangerMode: true,})
                }
            });
        });
    </script>
</block>
<block name="content">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>[ {$ad_position.name} ] - 广告列表</h5>
                        <div class="ibox-tools">
                            <a href="javascript:location.reload(true);" class="btn btn-outline btn-info btn-xs">
                                <i class="fa fa-refresh"></i> 刷新
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12 m-b-xs">
                                <div class="btn-group">
                                    <a href="{:url('ad/adLists')}"  class="btn btn-warning">
                                        <i class="glyphicon glyphicon-chevron-left"></i>  返回
                                    </a>
                                    <a href="javascript:;" data-url="{:url('ad/adItemSort')}" class="btn btn-success batchUpdate" type="button">更新排序</a>
                                    <a href="{:url('ad/createAdItem',['ad_position_id'=>$ad_position.ad_position_id])}" class="btn btn-info btn-rounded" type="button">新增</a>
                                </div>
                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                <tr>
                                    <th>序</th>
                                    <th>广告标题</th>
                                    <th>开始时间</th>
                                    <th>结束时间</th>
                                    <th>所属广告位</th>
                                    <th>排序</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <notempty name="adItem">
                                    <volist name="adItem" id="v">
                                        <tr>
                                            <td>{$i}</td>
                                            <td>{$v->title}</td>
                                            <td>{$v->start_time}</td>
                                            <td>{$v->end_time}</td>
                                            <td>{$v->ad_position->name}</td>
                                            <td><input type="text" class="form-control sortInput" name="sort[{$v['ad_item_id']}]" style="width: 50px;" value="{$v->sort}"></td>
                                            <td>{$v->status_text}</td>
                                            <td>
                                                <a href="{:url('ad/editAdItem',['ad_item_id'=>$v['ad_item_id']])}" class="btn btn-warning btn-sm">编辑</a>
                                                <a href="{:url('ad/deleteAdItem',['ad_item_id'=>$v['ad_item_id']])}" class="btn btn-danger btn-sm">删除</a>
                                            </td>
                                        </tr>
                                    </volist>
                                    <else />
                                    <tr>
                                        <td colspan="7" align="center">暂无数据!</td>
                                    </tr>
                                </notempty>

                                </tbody>
                            </table>
                        </div>
                        <notempty name="AdPosition">
                            {$adItem->render()}
                        </notempty>

                    </div>
                </div>
            </div>

        </div>
    </div>
</block>